<template>
  <!-- 修改面板 -->
  <el-dialog title="修改学科" :visible="dialogshow" width="25%">
    <el-form ref="form" :model="form" label-width="100px" :rules="rules">
      <el-form-item label="修改学科" prop="subjectName">
        <el-input v-model="form.subjectName"></el-input>
      </el-form-item>
      <el-form-item label="是否显示">
        {{ form.isFrontDisplay }}
        <span>不可见</span>
        <el-switch
          v-model="form.isFrontDisplay"
          active-color="#13ce66"
          inactive-color="#ff4949"
          active-value="1"
          inactive-value="0"
        >
        </el-switch>
        <span>可见</span>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="submit">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { update, add, list } from '@/api/hmmm/subjects.js'
export default {
  props: ['dialogshow'],
  data() {
    return {
      // 表单数据
      form: {
        subjectName: '',
        isFrontDisplay: ''
      },
      // 表单验证
      rules: {
        subjectName: [{ required: true, message: '请输入学科名', trigger: 'blur' }]
      }
    }
  },
  methods: {
    // 关闭面板
    cancel() {
      this.$emit('update:dialogshow', false)
      // 清空数据
      this.form = {
        subjectName: '',
        isFrontDisplay: ''
      }
    },
    getData(type) {
      this.form.type = type
    },
    async submit() {
      if (this.form) {
        // 数据提交到服务器
        await update(this.form)
      } else {
        // 新增数据
        add(this.form)
      }
      // 提示修改成功
      this.$message.success('修改成功')
      // 关闭面板
      this.$emit('update:dialogshow', false)
      // 更新数据
      this.$emit('updateData')
    },
    async list(id) {
      const res = await list(id)
      console.log(res)
      this.form = res.data.items
    }
  }
}
</script>

<style></style>
